package com.yunhe.authority.service.authority;

import com.yunhe.authority.domain.authority.Organization;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.exception.ObjectNotFoundException;
import com.yunhe.common.exception.UniqueConstraintsException;
import com.yunhe.common.model.PageParam;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zhengbo
 * @date 2021/2/24 10:19
 */
public interface OrganizationService {
    /**
     * 查询用户对应项目单位的协同组织
     * @param userId
     * @param stationId
     * @param firmId
     * @return
     */
    Iterable<Organization> findByUserId(Long userId, Long stationId, Long firmId);

    /**
     * 查询用户对应项目单位的归属组织
     * @param userId
     * @param stationId
     * @param firmId
     * @return
     */
    Iterable<Organization> findBelongOrgByUserId(Long userId, Long stationId, Long firmId);

    /**
     * 新增组织
     * @param parentId
     * @param organization 新增组织
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    Organization createOrganization(Long firmId, Long stationId, Long parentId, Organization organization) throws UniqueConstraintsException, ArgumentErrorException, ObjectNotFoundException;

    /**
     * 删除组织
     * @param ids 组织id列表
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    void deleteOrganization(List<Long> ids);

    /**
     * 修改组织
     * @param parentId
     * @param organization 新增组织
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    Organization updateOrganization(Long parentId, Organization organization) throws UniqueConstraintsException, ArgumentErrorException, ObjectNotFoundException;

    /**
     * 根据id查询组织
     * @param id 组织id
     * @return
     */
    Organization searchById(Long id);

    /**
     * 根据条件查询组织列表
     * @return
     */
    Page<Organization> searchByCondition(String name, String title, PageParam pageParam);

    /**
     * 根据项目id查询
     * @param stationId 项目id
     * @return
     */
    List<Organization> searchByStationId(Long stationId);


    /**
     * 根据项目id或单位id查询
     * @param stationId 项目id
     * @param firmId 单位id
     * @return List
     */
    List<Organization> searchByStationIdOrFirmId(Long stationId, Long firmId);


    /**
     * 组织绑定
     * @param stationId 项目id
     * @param firmId 单位di
     * @param id 组织id
     */
    @Transactional(rollbackFor = Exception.class, transactionManager = "transactionManager")
    void organizationBindAndUnbind(Long stationId, Long firmId, Long id) throws ArgumentErrorException;

    /**
     * 根据当前登录人获取当前登录人所在部门或者子部门
     * @param firmId
     * @param stationId
     * @param orgFunction
     * @param childFlag
     * @param orgType
     * @return
     */
    Iterable<Organization> getOrgByLoginUser(Long firmId, Long stationId, String orgFunction, Boolean childFlag, String orgType) throws ArgumentErrorException;

    Iterable<Organization> getSubOrg(String orgIdStr);

    List<Organization> searchOrgByStationId(Long stationId);

    List<Organization> findChildOrg(Long orgId, Long stationId);

    List<Organization> searchOrgByOrgFunction(String orgFunction) throws ArgumentErrorException;

    Iterable<Organization> findSynergyOrgByUserId(Long userId, Long stationId, Long firmId);

    List<Organization> getAllOrgByLoginUser(Boolean childFlag) throws ArgumentErrorException;

    List<Organization> getSubOrgByLoginUser(Long stationId, Long userId, Boolean childFlag);
}
